package com.deyang.mycommon.service;


import com.deyang.mycommon.config.HttpConfig;
import com.deyang.mycommon.entity.BaseResponse;
import com.deyang.mycommon.entity.DictResponse;
import com.deyang.mycommon.entity.Phone;
import com.deyang.mycommon.entity.TokenInfo;

import java.util.List;
import java.util.Map;

import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.Query;
import rx.Observable;

/**
 * @author 王德阳
 * @data 创建时间: 2018/5/4 0004
 * @Description 服务请求
 */
public interface IHttpService {

    String apiAuth = "api/auth";
    String apiDict = "api/dict";

//    String apiAdmin = "api/admin";
//    String rsecifUrl = "api/rsecif";

    /**
     * 登录
     *
     * @param userName  用户名
     * @param password  密码
     * @param grantType token登录方式
     * @return
     */
    @POST(apiAuth + "/oauth/token")
    @FormUrlEncoded
    @Headers({HttpConfig.HEADER_AUTH + ":Basic dnVlOnZ1ZQ=="})
    Observable<TokenInfo> login(@Field(HttpConfig.lOGIN_USER_NAME) String userName,
                                @Field(HttpConfig.lOGIN_PASSWORD) String password,
                                @Field(HttpConfig.GRANT_TYPE) String grantType);

    /**
     * 获取字典
     *
     * @param codes ,分割
     * @return
     */
    @GET(apiDict + "/dictValue/type/multiple/{codes}")
    Observable<BaseResponse<Map<String, List<DictResponse>>>> getDictByCodes(
            @Path(HttpConfig.DICT_CODES) String codes
    );

    /**
     * 手机归属地查询
     * 45ce719c42fdb25e
     */
    @POST("query")
    @FormUrlEncoded
//?appkey=45ce719c42fdb25e&shouji=17615825996
    Observable<BaseResponse<Phone>> postPhoneInfo(
            @Field("appkey") String appkey,
            @Field("shouji") String shouji
    );

    /**
     * 手机归属地查询
     * 45ce719c42fdb25e
     */
    @GET("query")
//?appkey=45ce719c42fdb25e&shouji=17615825996
    Observable<BaseResponse<Phone>> getPhoneInfo(
            @Query("appkey") String appkey,
            @Query("shouji") String shouji
    );

}
